#include "DownloadFileCmd.h"

DownloadFileCmd::DownloadFileCmd(QObject *parent) :
    BaseCmd(parent)
{
    this->m_protocolType = ProtocolType::CloudProtocol;
    this->m_functionCode = FunctionCode;
    this->m_fileType = 0;
}

Package DownloadFileCmd::toPackage()
{
    Package package;
    return package;
}

void DownloadFileCmd::unPackage(Package package)
{
    m_cmdId = package.id();
    QByteArray body;

    //body = decrypt(package.body(),KeyType::AES);

    quint16 index = 0;
    quint16 strLength;

    m_fileType = body.mid(index,1).toHex().toInt(0,16);
    index += 1;

    strLength = body.mid(index,2).toHex().toInt(0,16);
    index += 2;
    m_url = QString::fromUtf8(body.mid(index,strLength));
    index += strLength;

    strLength = body.mid(index,2).toHex().toInt(0,16);
    index += 2;
    QString temp = body.mid(index,strLength);

    QStringList paramList = temp.split("\n");
    paramList.removeOne("");
    foreach (const QString &param, paramList)
    {
        QStringList keyValue = param.split("=");
        m_paramMap.insert(keyValue.at(0),keyValue.at(1));
    }
}
quint8 DownloadFileCmd::fileType() const
{
    return m_fileType;
}

void DownloadFileCmd::setFileType(const quint8 &fileType)
{
    m_fileType = fileType;
}
QString DownloadFileCmd::url() const
{
    return m_url;
}

void DownloadFileCmd::setUrl(const QString &url)
{
    m_url = url;
}
QMap<QString, QString> DownloadFileCmd::paramMap() const
{
    return m_paramMap;
}

void DownloadFileCmd::setParamMap(const QMap<QString, QString> &paramMap)
{
    m_paramMap = paramMap;
}



